using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;


namespace XFGameFramework
{
     
    [Serializable]
    public class CollisionEvent : UnityEvent<Collision> { }
    [Serializable]
    public class CollisionEvent2D : UnityEvent<Collision2D> { }

    public class CollisionEventListener : MonoBehaviour
    {
        [SerializeField]
        private LayerMask layerMask; 
        // Fix编码  
        public CollisionEvent onCollisionEnter;
        public CollisionEvent onCollisionStay;
        public CollisionEvent onCollisionExit;
        public CollisionEvent2D onCollision2DEnter;
        public CollisionEvent2D onCollision2DStay;
        public CollisionEvent2D onCollision2DExit;



        private void Reset()
        {
            layerMask = Physics.AllLayers;
        }



        private void OnCollisionEnter(Collision collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollisionEnter?.Invoke(collision);
        }


        private void OnCollisionStay(Collision collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollisionStay?.Invoke(collision);
        }

        private void OnCollisionExit(Collision collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollisionExit?.Invoke(collision);
        }

        private void OnCollisionEnter2D(Collision2D collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollision2DEnter?.Invoke(collision);
        }

        private void OnCollisionStay2D(Collision2D collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollision2DStay?.Invoke(collision);
        }

        private void OnCollisionExit2D(Collision2D collision)
        {
            if (!layerMask.Contains(collision.gameObject.layer))
                return;
            onCollision2DExit?.Invoke(collision);
        }
         
    }

}
